package com.networklib.task.service;


import com.networklib.http.impl.ProgressResponseBodyImpl;
import com.networklib.task.base.TaskService;
import com.networklib.task.impl.DownloadHttpTask;
import com.networklib.task.base.ATask;

public class DownloadExcute extends ConcurrentExcute implements ProgressResponseBodyImpl.ProgressListener {
    private DownloadHttpTask downloadTask;

    @Override
    public final TaskService addTask(ATask aTask) {
        if (aTask instanceof DownloadHttpTask) {
            this.downloadTask = (DownloadHttpTask) aTask;
            this.submit(aTask);
            this.downloadTask.addDownProgressListener(this);
        }
        return this;
    }

    public ConcurrentExcute addTask(ATask... aTasks) {
        if (aTasks != null) {
            for (ATask aTask : aTasks) {
                if (aTask instanceof DownloadHttpTask) {
                    this.downloadTask = (DownloadHttpTask) aTask;
                    this.addTask(aTask);
                    this.downloadTask.addDownProgressListener(this);
                }
            }
        }
        return this;
    }

    @Override
    public void update(long bytesRead, long contentLength, boolean done) {
//        this.postProgress(this.downloadTask, (float)(100L * bytesRead / contentLength), done);
    }
}
